package document;

public class ManagingFAT {

	Disk disk=new Disk();
	public int[] findTheNullBlocks(int RecordSize){
		int[] blockNumberArray=new int[RecordSize];
		int j=0;
		//从FAT中读取数据
		int[] fat=new int[128];
		
		fat=disk.inputDiskToFat( );
		for(int i=3;i<128;i++){
			if(fat[i]==0)
				{blockNumberArray[j]=i;
				j++;
				}
			if(j>=RecordSize){
				break;
			}
		}
		int nullBlocks[]=new int[RecordSize+1];
		nullBlocks[0]=j;
		for(int i=1;i<=RecordSize;i++){
		int t=i-1;
		nullBlocks[i]=blockNumberArray[t];
		}
		//返回空块个数与空块块号
	    return nullBlocks;
		
	}
	
	
	public void ResetTheBlocks(int firstBlockNumber){
		int fat[]=new int[128];
		
		fat=disk.inputDiskToFat();
		int i ;
		for(i=firstBlockNumber;fat[i]==i+1;i++){
			fat[i]=0;
		}
		fat[i]=0;
		
		FileAllocationTable newFat = new FileAllocationTable();
		newFat.setFat(fat);
		disk.inputFatToDisk(newFat);

		
	}
	
	
	public static void main(String[] args) {
		
	}
	
	
}
